Skip to content

Add KV identity graph with CAS concurrency control (#536)#549

Closed
ChristianPavilonis wants to merge 1 commit intofeature/edge-cookiesfrom
feature/ec-kv-identity-graph
Closed

Add KV identity graph with CAS concurrency control (#536)#549
ChristianPavilonis wants to merge 1 commit intofeature/edge-cookiesfrom
feature/ec-kv-identity-graph

Conversation

@ChristianPavilonis
Copy link
Collaborator

Summary

  • Implements Story 3 (KV identity graph #536) of the Edge Cookie epic (Implement Edge Cookie (EC) identity system #532): adds KvIdentityGraph backed by Fastly KV Store with optimistic concurrency control (generation markers) for safe concurrent partner ID writes.
  • Defines the full KV schema (KvEntry, KvConsent, KvGeo, KvPartnerId, KvMetadata) with factory methods for initial, minimal recovery, and tombstone entries.
  • Tombstone guards in upsert_partner_id and update_last_seen prevent late syncs from repopulating partner IDs or extending TTL after consent withdrawal.

Closes #536

Changes

File Change
ec/kv.rs New. KvIdentityGraph struct with 8 methods: get, get_metadata, create, create_or_revive, upsert_partner_id, update_last_seen, write_withdrawal_tombstone, delete
ec/kv_types.rs New. Schema types with serde, factory methods (KvEntry::new, ::minimal, ::tombstone, KvMetadata::from_entry, KvGeo::from_geo_info), 14 unit tests
ec/mod.rs Added pub mod kv; pub mod kv_types; and module doc entries
fastly.toml Added ec_identity_store and ec_partner_store KV store declarations
trusted-server.toml Added ec_store and partner_store to [ec] section

Key design decisions

  • CAS via try_insert_add helper — Returns Ok(true) for created, Ok(false) for key-exists, Err for real failures. Avoids fragile string matching on error debug output.
  • Bounded retriesMAX_CAS_RETRIES = 3 for all CAS operations. No unbounded recursion.
  • Tombstone guardsupsert_partner_id rejects tombstoned entries; update_last_seen skips them. Prevents late syncs from resurrecting withdrawn consent.
  • 300s debounce on update_last_seen — Prevents write thrashing under bursty traffic (Fastly KV enforces 1 write/sec per key).
  • 24h tombstone TTL — Allows batch sync clients to distinguish consent_withdrawn from ec_hash_not_found.
  • Methods return Result — Callers decide error policy (swallow on organic paths, propagate on sync endpoints).

Verification

  • cargo fmt --all -- --check — clean
  • cargo clippy --workspace --all-targets --all-features -- -D warnings — zero warnings
  • cargo test --workspace729 tests passed, 0 failed (14 new tests for schema types + KV helpers)

@ChristianPavilonis ChristianPavilonis force-pushed the feature/edge-cookies branch 3 times, most recently from 2587b7a to e52ff39 Compare March 25, 2026 23:50
Implement Story 3 (#536): KV-backed identity graph with compare-and-swap
concurrency, partner ID upserts, tombstone writes for consent withdrawal,
and revive semantics. Includes schema types, metadata, 300s last-seen
debounce, and comprehensive unit tests.

Also incorporates earlier foundation work: EC module restructure, config
migration from [edge_cookie] to [ec], cookie domain computation, consent
gating fixes, and integration proxy revocation support.
@ChristianPavilonis ChristianPavilonis force-pushed the feature/ec-kv-identity-graph branch from 2f6c9e4 to a44ead1 Compare March 26, 2026 00:00
@ChristianPavilonis
Copy link
Collaborator Author

Superseded by #582 which consolidates the full EC epic into a single PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant